package org.bigjava.user.web.controller;


import org.bigjava.bean.Types;
import org.bigjava.user.service.impl.TypesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Controller
public class TypesController {
    @Autowired
    TypesServiceImpl service;


    //全部分类页面处理
    @RequestMapping("classify")
    public void classify(HttpSession session) {
        Map<String, Object> map = new HashMap<>();
        //查询所有一级分类名
        List<String> type = service.queryAllPrimaryClassification();

        //把所有的一级分类名作为map的key，查询出一级分类的所有二级分类打包成list放入value
        for (int i = 0; i < type.size(); i++) {
            List<String> twotypename = service.querySecondaryClassificationByone(type.get(i));
            map.put(type.get(i), twotypename);
        }
        //把所有一级二级分类存入ServletContext
        session.getServletContext().setAttribute("AllTypesName", map);
    }
}
